package conf

import (
	"time"
	"os"
	"bufio"
	"io"
	"strings"
	"encoding/json"
)

type Conf struct {
	Stime int `json:"time"`
}

func (c *Conf) Ticker() <-chan time.Time {
	tc := time.NewTicker(time.Duration(c.Stime) * time.Second)
	return tc.C
}

func InitConf(file string) Conf {
	f, err := os.Open(file)
	if err != nil {
		panic("文件读取失败")
	}
	r := bufio.NewReader(f)
	var f_str string
	for {
		s, err := r.ReadString('\n')
		f_str += strings.Trim(s, " \r\n")
		if err == io.EOF {
			break
		}
	}
	var conf Conf
	json.Unmarshal([]byte(f_str), &conf)
	return conf

}
